<template>
  <div class="login-container">
    <div class="login-form">
      <h2>登录</h2>
      <form @submit.prevent="handleLogin">
        <div class="form-group">
          <input type="text" id="username" v-model="username" placeholder="账号" required>
        </div>
        <div class="form-group">
          <input type="password" id="password" v-model="password" placeholder="密码" required>
        </div>
        <button type="submit">
          <span>登录</span>
        </button>
      </form>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const username = ref('')
const password = ref('')

const handleLogin = () => {
  if (username.value === 'nzp' && password.value === 'nzp') {
    localStorage.setItem('isLoggedIn', 'true')
    history.go(0)
  } else {
    alert('账号或密码错误')
  }
}
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: linear-gradient(to right, #4facfe, #00f2fe); /* 美化背景颜色 */
}

.login-form {
  background: white;
  padding: 40px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 400px;
}

.login-form h2 {
  margin: 0 0 30px;
  font-size: 28px;
  text-align: center;
  color: #1a1a1a;
}

.form-group {
  margin-bottom: 25px;
}

.form-group input {
  width: 100%;
  padding: 12px;
  font-size: 18px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  background: white;
  color: #1a1a1a;
  transition: border-color 0.3s ease;
}

.form-group input:focus {
  outline: none;
  border-color: #409eff;
}

.form-group input::placeholder {
  color: #a0a0a0;
}

button[type="submit"] {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 14px;
  font-size: 18px;
  font-weight: 500;
  color: white;
  background: #409eff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.3s ease;
}

button[type="submit"]:hover {
  background: #66b1ff;
}
</style> 